<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>登录</title>
	<link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<link href="http://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="css/htmleaf-demo.css">
	<style type="text/css">
		.form-bg{
		    padding: 2em 0;
		}
		.form-horizontal{
		    background: #fff;
		    padding-bottom: 40px;
		    border-radius: 15px;
		    text-align: center;
		}
		.form-horizontal .heading{
		    display: block;
		    font-size: 35px;
		    font-weight: 700;
		    padding: 35px 0;
		    border-bottom: 1px solid #f0f0f0;
		    margin-bottom: 30px;
		}
		.form-horizontal .form-group{
		    padding: 0 40px;
		    margin: 0 0 25px 0;
		    position: relative;
		}
		.form-horizontal .form-control{
		    background: #f0f0f0;
		    border: none;
		    border-radius: 20px;
		    box-shadow: none;
		    padding: 0 20px 0 45px;
		    height: 40px;
		    transition: all 0.3s ease 0s;
		}
		.form-horizontal .form-control:focus{
		    background: #e0e0e0;
		    box-shadow: none;
		    outline: 0 none;
		}
		.form-horizontal .form-group i{
		    position: absolute;
		    top: 12px;
		    left: 60px;
		    font-size: 17px;
		    color: #c8c8c8;
		    transition : all 0.5s ease 0s;
		}
		.form-horizontal .form-control:focus + i{
		    color: #00b4ef;
		}
		.form-horizontal .fa-question-circle{
		    display: inline-block;
		    position: absolute;
		    top: 12px;
		    right: 60px;
		    font-size: 20px;
		    color: #808080;
		    transition: all 0.5s ease 0s;
		}
		.form-horizontal .fa-question-circle:hover{
		    color: #000;
		}
		.form-horizontal .main-checkbox{
		    float: left;
		    width: 20px;
		    height: 20px;
		    background: #11a3fc;
		    border-radius: 50%;
		    position: relative;
		    margin: 5px 0 0 5px;
		    border: 1px solid #11a3fc;
		}
		.form-horizontal .main-checkbox label{
		    width: 20px;
		    height: 20px;
		    position: absolute;
		    top: 0;
		    left: 0;
		    cursor: pointer;
		}
		.form-horizontal .main-checkbox label:after{
		    content: "";
		    width: 10px;
		    height: 5px;
		    position: absolute;
		    top: 5px;
		    left: 4px;
		    border: 3px solid #fff;
		    border-top: none;
		    border-right: none;
		    background: transparent;
		    opacity: 0;
		    -webkit-transform: rotate(-45deg);
		    transform: rotate(-45deg);
		}
		.form-horizontal .main-checkbox input[type=checkbox]{
		    visibility: hidden;
		}
		.form-horizontal .main-checkbox input[type=checkbox]:checked + label:after{
		    opacity: 1;
		}
		.form-horizontal .text{
		    float: left;
		    margin-left: 7px;
		    line-height: 20px;
		    padding-top: 5px;
		    text-transform: capitalize;
		}
		.form-horizontal .btn{
		    float: right;
		    font-size: 14px;
		    color: #fff;
		    background: #00b4ef;
		    border-radius: 30px;
		    padding: 10px 25px;
		    border: none;
		    text-transform: capitalize;
		    transition: all 0.5s ease 0s;
		}
		@media only screen and (max-width: 479px){
		    .form-horizontal .form-group{
		        padding: 0 25px;
		    }
		    .form-horizontal .form-group i{
		        left: 45px;
		    }
		    .form-horizontal .btn{
		        padding: 10px 20px;
		    }
		}
	</style>
</head>
<body>
	<div class="htmleaf-container">
		
		<div class="demo form-bg">
	        <div class="container">
	            <div class="row">
	                <div class="col-md-offset-3 col-md-6">
						<!--  -->
	                    <form  id="loginform" class="form-horizontal" name="loginform" action="${pageContext.request.contextPath }/login.servlet" method="post">
	                        <span class="heading">用户登录</span>
	                        <div class="form-group">
	                            <input type="text" class="form-control" id="inputEmail3" name="username" placeholder="账号">
	                            <i class="fa fa-user"></i>
	                        </div>
	                        <div class="form-group help">
	                            <input type="password" class="form-control" id="inputPassword3" name="password" placeholder="密码">
	                            <i class="fa fa-lock"></i>
	                            <a href="#" class="fa fa-question-circle"></a>
	                        </div>
							<div class="form-group help">							   
								<canvas id="canvas" width="120" height="40px"></canvas>
								<input type="text" id="text" style="width: 120px; height: 30px;">
							</div>
	                        <div class="form-group">
	                            <div class="main-checkbox">
	                                <input type="checkbox" value="None" id="checkbox1" name="check"/>
	                                <label for="checkbox1"></label>
	                            </div>
	                            <span class="text">记住我</span>
	                            <button type="button" class="btn btn-default" id="bt">立刻登录</button>
	                        </div>
	                    </form>
						
						<!--  -->
	                </div>
	            </div>
	        </div>
	    </div>
		
	</div>


 <script>
        var canvas = document.getElementById("canvas");//演员
        var context = canvas.getContext("2d");//舞台，getContext() 方法可返回一个对象，该对象提供了用于在画布上绘图的方法和属性。
        var button = document.getElementById("bt");//获取按钮
        var input = document.getElementById("text");//获取输入框
        draw();
        canvas.onclick = function () {
            context.clearRect(0, 0, 120, 40);//在给定的矩形内清除指定的像素
            draw();
        }
        // 随机颜色函数
        function getColor() {
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + "," + g + "," + b + ")";
        }
        function draw() {
            context.strokeRect(0, 0, 120, 40);//绘制矩形（无填充）
            var aCode = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
            // 绘制字母
            var arr = [] //定义一个数组用来接收产生的随机数
            var num //定义容器接收验证码
            for (var i = 0; i < 4; i++) {
                var x = 20 + i * 20;//每个字母之间间隔20
                var y = 20 + 10 * Math.random();//y轴方向位置为20-30随机
                var index = Math.floor(Math.random() * aCode.length);//随机索引值
                var txt = aCode[index];
                context.font = "bold 20px 微软雅黑";//设置或返回文本内容的当前字体属性
                context.fillStyle=getColor();//设置或返回用于填充绘画的颜色、渐变或模式，随机
                context.translate(x,y);//重新映射画布上的 (0,0) 位置，字母不可以旋转移动，所以移动容器
                var deg=90*Math.random()*Math.PI/180;//0-90度随机旋转
                context.rotate(deg);// 	旋转当前绘图
                context.fillText(txt, 0, 0);//在画布上绘制“被填充的”文本
                context.rotate(-deg);//将画布旋转回初始状态
                context.translate(-x,-y);//将画布移动回初始状态
                arr[i] = txt //接收产生的随机数
            }
            num = arr[0] + arr[1] + arr[2] + arr[3] //将产生的验证码放入num
            // 绘制干扰线条
            for (var i = 0; i < 8; i++) {
                context.beginPath();//起始一条路径，或重置当前路径
                context.moveTo(Math.random() * 120, Math.random() * 40);//把路径移动到画布中的随机点，不创建线条
                context.lineTo(Math.random() * 120, Math.random() * 40);//添加一个新点，然后在画布中创建从该点到最后指定点的线条
                context.strokeStyle=getColor();//随机线条颜色
                context.stroke();// 	绘制已定义的路径
            }
            // 绘制干扰点，和上述步骤一样，此处用长度为1的线代替点
            for (var i = 0; i < 20; i++) {
                context.beginPath();
                var x = Math.random() * 120;
                var y = Math.random() * 40;
                context.moveTo(x, y);
                context.lineTo(x + 1, y + 1);
                context.strokeStyle=getColor();
                context.stroke();
            }

            //点击按钮验证
            button.onclick = function () { 
				// debugger;
            var text = input.value //获取输入框的值
            if(text != num) {
                alert('验证码错误!');
				return false;
            }

			document.getElementById("loginform").submit();
			
         }
            
        }

    </script>
</body>
</html>